package offer;

/*
* P38 面试题3： 二维数组中的查找
* */
public class FindIn2DArray {

    public static boolean find(int[][] arr, int num){
        if(arr == null || arr.length < 1){
            return  false;
        }
        int row = arr.length - 1;
        int col = arr[0].length - 1;

        int curRow = 0;
        int curCol = col;
        boolean isFind = false;
        while(curRow <= row && curCol >= 0){

            if(arr[curRow][curCol] == num){
                isFind = true;
                break;
            }else if(arr[curRow][curCol] > num){
                curCol --;
            } else {
                curRow ++;
            }
        }

        return isFind;
    }
}
